﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LX.Web.Excel;
using S4Store.Domain.AfterSaleKpi;

namespace S4Store.Domain.AfterSaleReport
{
    public class CSReport: ExportObject
    {

        #region 数据导出
        public override bool? Discriminate(string propertyname)
        {
            if (propertyname == "WXKHHFL")
            {
                return this.WXKHHFL > StandardConfig.维修客户回访率目标;
            }

            if (propertyname == "LYWHCKHHFL")
            {
                return this.LYWHCKHHFL > StandardConfig.六月未回厂客户回访率目标;
            }

            if (propertyname == "SYWHCKHHFL")
            {
                return this.SYWHCKHHFL > StandardConfig.四月未回厂客户回访率目标;
            }
            if (propertyname == "LSKHHGL")
            {
                return this.LSKHHGL > StandardConfig.流失客户回归率目标;
            }
            return null;
        }
        #endregion


        public int Year { get; set; }
        public int Month { get; set; }
        public int Day { get; set; }

        public MonthStandardConfig StandardConfig { get; set; }

        public List<AfterSaleServiceAdvisorMonthTarget> M { get; set; }
        public List<AfterSaleServiceAdvisorDayInput> D { get; set; }

        public List<AfterSaleCustomerServiceDayInput> CD { get; set; }

        public Store Store { get; set; }

        protected bool showlastday = false;
        public virtual void ShowLastDay(bool value)
        {
            showlastday = value;
        }

        [Export("职员姓名")]
        public string EmployName
        {
            get;
            set;
        }

        [Export("客服专员职业资质", Format = "{0}年")]
        public int WorkYear
        {
            get;
            set;
        }

        [Export("人数")]
        public int RS
        {
            get {
                return 1;
            }
        }

        public int ZRS
        {
            get;
            set;
        }

        #region 服务顾问
        [Export("上月末分管客户总数")]
        public int SYMFGKHZS
        {
            get
            {
                return M.Sum(o => o.SYMFGKHZS_LastMonthManageCustomerNum);
            }
        }

        [Export("月初六月未回厂数")]
        public int YCLYWHCS
        {
            get
            {
                return M.Sum(o => o.LGYWHCZS);
            }
        }

        [Export("本月新增六个月未回厂数")]
        public int BYXZLGYWHCS
        {
            get
            {
                return D.Sum(o => o.XZLGYWHCS);
            }
        }

        [Export("六个月未回厂客户总数")]
        public int LGYWHCKHZS
        {
            get
            {
                return YCLYWHCS + BYXZLGYWHCS - LSKHCXHCS;
            }
        }

        [Export("月初四个月未回厂数")]
        public int YCSGYWHCS
        {
            get
            {
                return M.Sum(o => o.SGYWHCZS);
            }
        }

        [Export("本月新增四个月未回厂数")]
        public int BYXZSGYWHCS
        {
            get
            {
                return D.Sum(o => o.XZSGYWHCS);
            }
        }

        [Export("四个月未回厂客户总数")]
        public int SGYWHCKHZS
        {
            get
            {
                return YCSGYWHCS + BYXZSGYWHCS;
            }
        }

        [Export("本月A卡转C卡客户数")]
        public int BYAKZCKKHS
        {
            get
            {
                return D.Sum(o => o.BYAKZCKKHS_ACard2CCard);
            }
        }

        [Export("分管保有客户总数")]
        public int FGBYKHZS
        {
            get
            {
                return SYMFGKHZS + BYAKZCKKHS - LGYWHCKHZS;
            }
        }        

        [Export("本月应实施5K保养数")]
        public int BYYSS5KBYS
        {
            get
            {
                return M.Sum(o => o.BYYSSWKBYS_5KMaintenceTarget);
            }
        }

        [Export("本月应实施10K保养数")]
        public int BYYSS10KBYS
        {
            get
            {
                return M.Sum(o => o.BYYSSSQBYS_10KMaintenceTarget);
            }
        }

        [Export("本月招徕回厂目标数")]
        public int BYZLHCMBS
        {
            get
            {
                return M.Sum(o => o.BYYZHCMBS_ReturnFactoryTarget);
            }
        }

        [Export("本月目标预约入厂台次")]
        public int BYMBYYRCTC
        {
            get
            {
                return 0;
            }
        }

        [Export("本月事故车入厂台次目标")]
        public int BYSGCRCTCMB
        {
            get
            {
                return M.Sum(o => o.BYSGCRCTCMB_AccidentCarToFactoryTarget);
            }
        }

        [Export("本月维修入厂台次目标")]
        public int BYWXRCTCMB
        {
            get
            {
                return M.Sum(o => o.BYWXRCTCMB_MaintenceCarToFactoryTarget);
            }
        }

        [Export("目标入厂台次")]
        public int MBRCTC
        {
            get
            {
                return M.Sum(o => o.BYYSSWKBYS_5KMaintenceTarget + o.BYYSSSQBYS_10KMaintenceTarget + o.BYSGCRCTCMB_AccidentCarToFactoryTarget + o.BYWXRCTCMB_MaintenceCarToFactoryTarget);
            }
        }

        [Export("本月事故车产值目标")]
        public decimal BYSGCCZMB
        {
            get
            {
                return M.Sum(o => o.BYSGCCZMB_AccidentCarValueTarget);
            }
        }

        [Export("本月维修产值目标")]
        public decimal BYWXCZMB
        {
            get
            {
                return M.Sum(o => o.BYWXCZMB_MaintenceValueTarget);
            }
        }

        [Export("目标售后产值")]
        public decimal MBSHCZ
        {
            get
            {
                return M.Sum(o => o.BYWXCZMB_MaintenceValueTarget + o.BYSGCCZMB_AccidentCarValueTarget);
            }
        }

        [Export("精品目标销售额")]
        public decimal JPMBXSE
        {
            get
            {
                return M.Sum(o => o.JPMBXSE_CompetitiveSaleTarget);
            }
        }

        [Export("养护产品目标销售额")]
        public decimal YHCPMBXSE
        {
            get
            {
                return M.Sum(o => o.YHCPMBXSE_MaintenceSaleTarget);
            }
        }

        [Export("首次续保台次目标")]
        public int SCXBTCMB
        {
            get
            {
                return M.Sum(o => o.SCXBTCMB_FirstRenewTarget);
            }
        }

        [Export("二次续保台次目标")]
        public int ECXBTCMB
        {
            get
            {
                return M.Sum(o => o.ECXBTCMB_SecondRenewTarget);
            }
        }

        [Export("目标续保台次总数")]
        public int MBXBTCZS
        {
            get
            {
                return SCXBTCMB + ECXBTCMB;
            }
        }

        [Export("客户满意度考核目标")]
        public int KHMYDKHMB
        {
            get
            {
                return M.Sum(o => o.KHMYDKHMB_CustomerSatisfactionTarget);
            }
        }

        [Export("累计完成事故入厂台次")]
        public int LJWCSGRCTC
        {
            get
            {
                return D.Sum(o => o.SGRCTC_AccidentToFactory);
            }
        }

        [Export("累计完成维修入厂台次")]
        public int LJWCWXRCTC
        {
            get
            {
                return D.Sum(o => o.WXRCTC_MaintentceToFactory);
            }
        }

        [Export("累计完成入厂台次")]
        public int LJWCRCTC
        {
            get
            {
                return D.Sum(o => o.WXRCTC_MaintentceToFactory + o.SGRCTC_AccidentToFactory);
            }
        }

        [Export("累计完成事故车产值")]
        public decimal LJWCSGCCZ
        {
            get
            {
                return D.Sum(o => o.SGCCZ_AccidentCarValue);
            }
        }

        [Export("累计完成维修产值")]
        public decimal LJWCWXCZ
        {
            get
            {
                return D.Sum(o => o.WXCZ_MaintenceValue);
            }
        }

        [Export("累计完成售后产值")]
        public decimal LJWCSHCZ
        {
            get
            {
                return D.Sum(o => o.WXCZ_MaintenceValue + o.SGCCZ_AccidentCarValue);
            }
        }

        [Export("本月实际实施5K保养数")]
        public int BYSJSS5KBYS
        {
            get
            {
                return D.Sum(o => o.SSWQBYS_5KMaintenceNum);
            }
        }

        [Export("本月实际实施10K保养数")]
        public int BYSJSS10KBYS
        {
            get
            {
                return D.Sum(o => o.SSSQBYS_10KMaintenceNum);
            }
        }

        [Export("成功实施招徕客户数")]
        public int CGSSZLKHS
        {
            get
            {
                return D.Sum(o => o.DHZLKHS_InviteByTelNum);
            }
        }

        [Export("电话成功预约回厂数")]
        public int DHCGYYHCS
        {
            get
            {
                return D.Sum(o => o.DHCGYYHCS);
            }
        }

        [Export("累计实现预约回厂数")]
        public int LJSXYYHCS
        {
            get
            {
                return D.Sum(o => o.SXYYHCS);
            }
        }

        [Export("准时交车客户数")]
        public int ZSJCKHS
        {
            get
            {
                return D.Sum(o => o.ZSJCKHS);
            }
        }

        [Export("当日交车客户数")]
        public int DRJCKHS
        {
            get
            {
                return D.Sum(o => o.DRJCKHS);
            }
        }

        [Export("累计精品销售额")]
        public decimal LJJPXSE
        {
            get
            {
                return D.Sum(o => o.LJJPXSE);
            }
        }

        [Export("累计养护产品销售额")]
        public decimal LJYHCPXSE
        {
            get
            {
                return D.Sum(o => o.LJYHCPXSE);
            }
        }

        [Export("首次续保实际完成台次")]
        public int SCXBSJWCTC
        {
            get
            {
                return D.Sum(o => o.SCXBSJWCTC);
            }
        }

        [Export("二次续保实际完成台次")]
        public int ECXBSJWCTC
        {
            get
            {
                return D.Sum(o => o.ECXBSJWCTC);
            }
        }

        [Export("续保台次完成总数")]
        public int XBTCWCZS
        {
            get
            {
                return D.Sum(o => o.ECXBSJWCTC + o.SCXBSJWCTC);
            }
        }

        [Export("流失客户重新回厂数")]
        public int LSKHCXHCS
        {
            get
            {
                return D.Sum(o => o.LSKHCXHCS);
            }
        }

        #endregion

        [Export("本月累计入厂台次")]
        public int BYLJRCTC
        {
            get
            {
                if (ZRS == 0) return 0;
                return LJWCRCTC / ZRS;
            }
        }

        [Export("本月新增六月未回厂客户数")]
        public int BYXZLYWHCKHS
        {
            get
            {
                if (ZRS == 0) return 0;
                return LGYWHCKHZS / ZRS;
            }
        }

        [Export("本月新增四月未回厂客户数")]
        public int BYXZSYWHCKHS
        {
            get
            {
                if (ZRS == 0) return 0;
                return SGYWHCKHZS / ZRS;
            }
        }

        [Export("累计维修后回访数")]
        public int LJWXHHFS
        {
            get
            {
                return CD.Sum(o => o.LJWXHHFS);
            }
        }

        [Export("六月未回厂客户回访数")]
        public int LYWHCKHHFS
        {
            get
            {
                return CD.Sum(o => o.LYWHCKHHFS);
            }
        }

        [Export("四月未回厂客户回访数")]
        public int SYWHCKHHFS
        {
            get
            {
                return CD.Sum(o => o.SYWHCKHHFS);
            }
        }

        [Export("流失客户重新回厂数1")]
        public int LSKHCXHCS1
        {
            get
            {
                return CD.Sum(o => o.LSKHCXHCS);
            }
        }

        [Export("维修客户回访率", Format="{0}%", BackBround= ExcelCellBg.Warning)]
        public decimal WXKHHFL
        {
            get
            {
                if (BYLJRCTC == 0) return 0;
                return (decimal)LJWXHHFS / (decimal)BYLJRCTC*100;
            }
        }

        [Export("六月未回厂客户回访率", Format = "{0}%", BackBround = ExcelCellBg.Warning)]
        public decimal LYWHCKHHFL
        {
            get
            {
                if (BYXZLYWHCKHS == 0) return 0;
                return (decimal)LYWHCKHHFS / (decimal)BYXZLYWHCKHS*100;
            }
        }

        [Export("四月未回厂客户回访率", Format = "{0}%", BackBround = ExcelCellBg.Warning)]
        public decimal SYWHCKHHFL
        {
            get
            {
                if (BYXZSYWHCKHS == 0) return 0;
                return (decimal)SYWHCKHHFS / (decimal)BYXZSYWHCKHS*100;
            }
        }

        [Export("流失客户回归率", Format = "{0}%", BackBround = ExcelCellBg.Warning)]
        public decimal LSKHHGL
        {
            get
            {
                if (BYXZLYWHCKHS == 0) return 0;
                return (decimal)LSKHCXHCS1 / (decimal)BYXZLYWHCKHS*100;
            }
        }

    }
}
